<?php

// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitAddress extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('addresses', function (Blueprint $table) {
            $table->comment = '地址表';
            
            $table->increments('id');
            $table->uuid('uuid')->index() ;
            $table->integer('user_id')->unsigned()->index();

            $table->string('country', 100)->nullable()->comment('国家');
            $table->string('province', 100)->nullable()->comment('省份');
            $table->string('city', 100)->nullable()->comment('市');
            $table->string('district', 100)->nullable()->comment('地区');
            $table->string('address', 100)->nullable()->comment('详细地址');

            $table->string('tag', 20)->nullable()->comment('标签');

            $table->string('consignee', 100)->nullable()->comment('收件人'); // 收件人
            $table->string('phone', 30)->nullable()->comment('手机号');
            $table->string('tel', 50)->nullable()->comment('电话');
            $table->string('zipcode', 30)->nullable()->comment('邮编');

            $table->boolean('is_default')->default(0)->comment('是否默认地址');

            $table->softDeletes();
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('addresses');
    }
}
